package com.v2future.sjt.collegecheckingattendance.leave;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.MainActivity;
import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.common.activity.DatePickerActivity;
import com.v2future.sjt.collegecheckingattendance.common.tag.CacheIntents;
import com.v2future.sjt.collegecheckingattendance.leave.adapter.CourseAdapter;
import com.v2future.sjt.collegecheckingattendance.leave.bean.CourseUnitBean;
import com.v2future.sjt.collegecheckingattendance.leave.bean.CoursesBean;
import com.v2future.sjt.collegecheckingattendance.leave.bean.TeacherBean;
import com.v2future.sjt.collegecheckingattendance.utils.CalculateTime;
import com.v2future.sjt.collegecheckingattendance.utils.Constants;
import com.v2future.sjt.collegecheckingattendance.utils.DateUtil;
import com.v2future.sjt.collegecheckingattendance.utils.IntentKey;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.NetTaskListener;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.NetUtils;
import com.v2future.sjt.collegecheckingattendance.widget.ListViewInScroll;

import org.xutils.http.RequestParams;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/2/17.
 * 课程请假界面
 * 2016.10.8 修改课程列表为手动填写课程
 */
public class CourseLeaveActivity extends MainActivity implements View.OnClickListener{

    protected Button nextBtn;

    private EditText courseNameEt;

    /**
     * 选中日期
     */
    private String selectDate;

    /**
     * 填写的课程名称
     */
    private String courseName;

    /**
     * 界面回送数据接收标识
     */
    //日期回送
    public static final String BACKTAG_DATE_SELECT = "dateSelect";

    private TeacherBean teacherBean;

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (BACKTAG_DATE_SELECT.equals(intent.getAction())) {
            selectDate = intent.getStringExtra(DatePickerActivity.TAG_SELECT_DATE);
            if (CalculateTime.compare_date(selectDate, DateUtil.getCurrentDateYMD()) <= 0) {
                setTitleText(selectDate);
//                doGetCourse(selectDate);
            }
            else {
                showSimpleDialog("不能请过去的假哦~");
            }
        }
    }

    @Override
    public void init() {
        teacherBean = (TeacherBean) getIntent().getSerializableExtra(IntentKey.TEACHER);
        selectDate = DateUtil.getCurrentDateYMD();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_leave_class);
        initTitleBack(null);
        setTitleText(selectDate);//设置日期为今天
        setRightIcon(R.mipmap.icon_calendar, this);
        courseNameEt = (EditText) findViewById(R.id.et_course_name);
        nextBtn = (Button) findViewById(R.id.btn_next);
        nextBtn.setOnClickListener(this);
    }

    @Override
    public void initAfter() {

    }


    /**
     * 跳转到日期选择页
     */
    public void jumpToCalendar(){
        Intent dateIntent = new Intent(this, DatePickerActivity.class);
        dateIntent.putExtra(DatePickerActivity.TAG_SELECT_DATE, DateUtil.getCurrentDateYMD());
        dateIntent.putExtra(DatePickerActivity.TAG_LEAVE_TYPE, DatePickerActivity.LEAVE_TYPE_COURSE);
        startActivity(dateIntent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_next:
                courseName = courseNameEt.getText().toString();
                if (TextUtils.isEmpty(courseName.trim())) {
                    tip("请填写请假课程名称");
                    break;
                }
                Intent uploadPicIntent = new Intent(this, CourseLeaveFillinInfoActivity.class);
                getBaseApplication().insertIntentData(CacheIntents.COURSELEAVE_DATE, selectDate);
                getBaseApplication().insertIntentData(CacheIntents.COURSELEAVE_COURSE_NAME, courseName);
                getBaseApplication().insertIntentData(IntentKey.TEACHER, teacherBean);
                startActivity(uploadPicIntent);
                break;
            case R.id.layout_right:
                jumpToCalendar();
                break;
            default:
                break;
        }
    }

}
